package com.java.ssm.service.impl;

import com.java.ssm.entity.Warehousing;
import com.java.ssm.dao.WarehousingDao;
import com.java.ssm.service.WarehousingService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Warehousing)表服务实现类
 *
 * @author makejava
 * @since 2021-01-18 11:12:33
 */
@Service("warehousingService")
public class WarehousingServiceImpl implements WarehousingService {
    @Resource
    private WarehousingDao warehousingDao;

    @Override
    public List<Warehousing> getAllRu() {
        return warehousingDao.getAllRu();
    }

    @Override
    public List<Warehousing> getAll() {
        List<Warehousing> all = warehousingDao.getAll();
        return  all;
    }

    /**
     * 通过ID查询单条数据
     *
     * @param wId 主键
     * @return 实例对象
     */
    @Override
    public Warehousing queryById(Integer wId) {
        return this.warehousingDao.queryById(wId);
    }


    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<Warehousing> queryAllByLimit(int offset, int limit) {
        return this.warehousingDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param warehousing 实例对象
     * @return 实例对象
     */
    @Override
    public Warehousing insert(Warehousing warehousing) {
        this.warehousingDao.insert(warehousing);
        return warehousing;
    }

    @Override
    public List<Warehousing> queryAll(Warehousing warehousing) {

        return warehousingDao.queryAll(warehousing);
    }

    @Override
    public List<Warehousing> queryAllLike(String oNumber,String sName) {
        return warehousingDao.queryAllLike(oNumber,sName);
    }

    /**
     * 修改数据
     *
     * @param warehousing 实例对象
     * @return 实例对象
     */
    @Override
    public Warehousing update(Warehousing warehousing) {
        this.warehousingDao.update(warehousing);
        return this.queryById(warehousing.getwId());
    }

    @Override
    public int getRUp(Integer id) {
        Warehousing warehousing = warehousingDao.queryById(id);
        int rUp;
        if(warehousing.getwRdel()==1){
             rUp= warehousingDao.getRUp(id, 0);
        }else{
             rUp= warehousingDao.getRUp(id,1);
        }
        return rUp;
    }

    /**
     * 通过主键删除数据
     *
     * @param wId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer wId) {
        return this.warehousingDao.deleteById(wId) > 0;
    }
}